// SiteTable.cpp: implementation of the SiteTable class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "SiteTable.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
using namespace PDMS::PDMSDBIF;

BEGIN_REGISTER_MAP( SiteTable, MultiRecordsDatabaseElement)
REGISTER( _T("SiteData"), GET_REGISTER( DatabaseElementFactory, Design_VersionOne ) )
END_REGISTER_MAP();
SiteTable::SiteTable()
{

}

SiteTable::~SiteTable()
{

}

void SiteTable::SetID( unsigned long lID )
{
	m_pCurRecord->SetID( lID );
}

void SiteTable::SetParentID( unsigned long lParentID )
{
	m_pCurRecord->SetParentID( lParentID );
}

void SiteTable::SetDescription( const StdString& strDescription )
{
	m_pCurRecord->SetDescription( strDescription );
}

void SiteTable::SetPurpose( const StdString& strPurpose )
{
	m_pCurRecord->SetPurpose( strPurpose );
}

void SiteTable::SetFunction( const StdString& strFunction )
{
	m_pCurRecord->SetFunction( strFunction );
}

void SiteTable::SetNumber( int iNumber )
{
	m_pCurRecord->SetNumber( iNumber );
}

void SiteTable::SetArea( int iArea )
{
	m_pCurRecord->SetArea( iArea );
}

void SiteTable::SetModule( const StdString& strModule )
{
	m_pCurRecord->SetModule( strModule );
}

void SiteTable::SetRlstored( const StdString& strRlstored )
{
	m_pCurRecord->SetRlstored( strRlstored );
}

unsigned long SiteTable::GetID()
{
	return m_ResPtr->GetLong( _T("ID"));
}

unsigned long SiteTable::GetParentID()
{
	return m_ResPtr->GetLong( _T("ParentID") );
}

const StdString SiteTable::GetDescription()
{
	return m_ResPtr->GetString( _T("Description") );
}

const StdString SiteTable::GetPurpose()
{
	return m_ResPtr->GetString( _T("Purpose") );
}

const StdString SiteTable::GetFunction()
{
	return m_ResPtr->GetString( _T("Function") );
}

int SiteTable::GetNumber()
{
	return (int)m_ResPtr->GetLong( _T("Number") );
}

int SiteTable::GetArea()
{
	return (int)m_ResPtr->GetLong( _T("Area") );
}

const StdString SiteTable::GetModule()
{
	return m_ResPtr->GetString( _T("Module") );
}

const StdString SiteTable::GetRlstored()
{
	return m_ResPtr->GetString( _T("Rlstored") );
}

StdString SiteTable::GetOpenSQL( const StdString& strCondition )
{
	StdString strTemp( _T("Select * from SiteData ") );
	if ( strCondition == ALLRECORD )
	{
		return strTemp;
	}
	
	return strTemp + _T("Where ") + strCondition;
}

StdString SiteTable::GetTableName()
{
	return StdString( _T("SiteData") );
}

void SiteTable::SetData( RecordPtr_ ptr )
{
	ASSERT( ptr != NULL );

	if ( ptr->IsIDModified() )
	{
		m_ResPtr->SetLong( _T( "ID" ), ptr->GetID() );
	}
	if ( ptr->IsParentIDModified() )
	{
		m_ResPtr->SetLong( _T( "ParentID" ), ptr->GetParentID() );
	}
	if ( ptr->IsDescriptionModified() )
	{
		m_ResPtr->SetString( _T( "Description" ), ptr->GetDescription() );
	}
	if ( ptr->IsPurposeModified() )
	{
		m_ResPtr->SetString( _T( "Purpose" ), ptr->GetPurpose() );
	}
	if ( ptr->IsFunctionModified() )
	{
		m_ResPtr->SetString( _T( "Function" ), ptr->GetFunction() );
	}
	if ( ptr->IsNumberModified() )
	{
		m_ResPtr->SetLong( _T( "Number" ), ptr->GetNumber() );
	}
	m_ResPtr->SetLong( _T( "Area" ), ptr->GetArea() );
	m_ResPtr->SetString( _T( "Module" ), ptr->GetModule() );
	m_ResPtr->SetString( _T( "Rlstored" ), ptr->GetRlstored() );
}